import Koa from 'koa';
import bodyParser from 'koa-bodyparser';
import cors from 'koa-cors';
import responseMiddleware from './middleware/response.js';
import registerRoutes from './routes/index.js';

const app = new Koa();

// 使用中间件
app.use(cors());
app.use(bodyParser());
app.use(responseMiddleware);

// 注册所有路由
registerRoutes(app);

// 错误事件监听
app.on('error', (err) => {
  console.error('server error', err);
});

const PORT = 3000;
app.listen(PORT, () => {
  console.log(`服务器运行在 http://localhost:${PORT}`);
}); 